//
//  ViewController.m
//  18-SQLite
//
//  Created by dllo on 16/8/8.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ViewController.h"
#import "SQLiteDataBaseManager.h"
#import "Student.h"

@interface ViewController ()
@property (nonatomic,strong) SQLiteDataBaseManager *dataBaseManager;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    _dataBaseManager = [SQLiteDataBaseManager shareManager];
//    使用sqlite需要引入libsqlite3.0.tbd
//    libsqlite3.0.tbd和libsqlite3.tbd
//    3.0是3的替身文件防止用户误删
    
}
- (IBAction)openSQLite:(id)sender {
    [_dataBaseManager openSQLite3];
    
    
}

- (IBAction)closeSQLite:(id)sender {
    [_dataBaseManager closeSQLite3];
}

- (IBAction)creatSQLite:(id)sender {
    [_dataBaseManager createSQLite];
    
    
    
}

- (IBAction)addSQLite:(id)sender {
    Student *stu = [[Student alloc] init];
    stu.stu_id = 38;
    stu.stu_name = @"狐狸";
    [_dataBaseManager insertStu:stu];
}

- (IBAction)removeSQLite:(id)sender {

    Student *stu = [[Student alloc] init];
    stu.stu_id = 38;
    stu.stu_name = @"狐狸";
    [_dataBaseManager deleteStu:stu];
    
    [_dataBaseManager deleteAll];
}


- (IBAction)updateName:(id)sender {
    [_dataBaseManager updateOldName:@"狐狸" newName:@"飞天"];
    
}

- (IBAction)selectAll:(id)sender {
NSArray *array = [_dataBaseManager selectAll];
    NSLog(@"%ld",array.count);
     NSLog(@"%@",array);
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
